package algorithm.sort;

import java.math.BigDecimal;
import java.util.*;

public class SortDemo {

    public static void sortE(List<Employee> employeeList) {
        Comparator<Employee> byLevel = Comparator.comparing(Employee::getLevel).reversed();
        Comparator<Employee> byWorkAge = Comparator.comparing(Employee::getWorkAge).reversed();
        Comparator<Employee> bySalary = Comparator.comparing(Employee::getSalary).reversed();
        employeeList.sort(byLevel.thenComparing(bySalary).thenComparing(byWorkAge));
        for (Employee e : employeeList) {
            System.out.println(e);
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Employee> employeeList = new ArrayList<>();
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            Employee e = new Employee();
            String name = scanner.next();
            e.setName(name);
            int level = scanner.nextInt();
            e.setLevel(level);
            int workAge = scanner.nextInt();
            e.setWorkAge(workAge);
            double salary = scanner.nextDouble();
            e.setSalary(salary);
            employeeList.add(e);
        }
        sortE(employeeList);
    }
}

class Employee {
    private String name;
    private int level;
    private int workAge;
    private double salary;

    public Employee(String name, int level, int workAge, double salary) {
        this.name = name;
        this.level = level;
        this.workAge = workAge;
        this.salary = salary;
    }

    public Employee() {
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getLevel() {
        return this.level;
    }

    public void setWorkAge(int workAge) {
        this.workAge = workAge;
    }

    public int getWorkAge() {
        return this.workAge;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public double getSalary() {
        return this.salary;
    }

    @Override
    public String toString() {
        String v = new BigDecimal(salary).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
        return name + " " + level + " " + workAge + " " + v;
    }
}
